package com.xwkj.sharding.controller;

import com.xwkj.sharding.entity.OrderEntity;
import com.xwkj.sharding.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    // 使用in条件查询
    @RequestMapping("/inOrder")
    public List<OrderEntity> findExpiredOrderState() {
        List<String> ids = new ArrayList<>();
        ids.add("2");
        ids.add("3");
        ids.add("4");
        ids.add("5");
        return orderService.findExpiredOrderState(ids);
    }

    // 查询所有的订单信息
    @RequestMapping("/getOrderAll")
    public List<OrderEntity> getOrderAll() {
        return orderService.findAll();
    }

    @RequestMapping("/inserOrder")
    public String inserOrder(OrderEntity orderEntity) {
        for (int i = 0; i < 10; i++) {
            OrderEntity order = new OrderEntity();
            order.setOrderId((long) i);
            order.setUserId((long) i);
            orderService.save(order);
        }
        return "success";
    }
}
